package cn.kgc.service;

import cn.kgc.entity.User;
import cn.kgc.entity.UserPage;
import cn.kgc.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 郝雷蒙
 * @Description
 * @date 2020/12/24 21:24
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
 private UserMapper userMapper;

    @Override
    public UserPage getAllUsers(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        List<User> userList = userMapper.selectAllUsers();

        PageInfo<User> pageInfo = new PageInfo<>(userList);

        UserPage userPage = new UserPage();
        userPage.setUserList(userList);
        userPage.setPageCount(pageInfo.getPages());
        userPage.setRowCount((int)pageInfo.getTotal());
        userPage.setPageNum(pageNum);
        userPage.setPageSize(pageSize);
        return userPage;
    }
}
